package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark37Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark37 extends BaseMark {

    LayoutWatermark37Binding binding;

    public Mark37(@NonNull Context context) {
        super(context);
    }

    public Mark37(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark37(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark37Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark37Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.item73Author, binding.item73Remark);
        }
    }

    @Override
    public void update() {
        setText(binding.item73Temperature, "temp37", binding.binding2);
        setText(binding.item73Weather, "weather37", binding.item73Weather);
        setText(binding.item73Time, "time37", binding.item73Relayout);
        setTime(binding.item73Time, new SimpleDateFormat("HH:mm"));
        setWeek(binding.item73Week);
        setTime(binding.item73Date, new SimpleDateFormat("MM/dd"));

        setText(binding.item73Address, "didian37", binding.item73Address);
        setText(binding.item73Author, "author37", binding.item73Author);
        setText(binding.item73Remark, "beizhu37", binding.item73Remark);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("temp37", "温度"));
        list.add(new EditItem("weather37", "天气"));
        list.add(new EditItem("time37", "时间", true));
        list.add(new EditItem("didian37", "地点"));
        list.add(new EditItem("author37", "拍摄者"));
        list.add(new EditItem("beizhu37", "备注"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.item73Time, new SimpleDateFormat("HH:mm"));
            setWeek(binding.item73Week);
            setTime(binding.item73Date, new SimpleDateFormat("MM/dd"));
        } else {
            super.onValueChange(item);
        }
    }
}
